<?php $this->display('header') ?>
<link href="{$_W['siteroot']}../addons/{MOD_ADD}/static/admin/H/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
</head>
<body>
<div id="wrapper">
    <!--左侧导航开始-->
    <?php $this->display('menu') ?>
    <!--左侧导航结束-->
    <!--右侧部分开始-->
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <?php $this->display('header_top') ?>
            <div class="row wrapper border-bottom white-bg page-heading">
                <form action="{php echo gWebUrl('auths/lists')}" method="post" class="form-horizontal" role="form" id="formdata">
                    <div class="ibox float-e-margins">
                        <div class="col-xs-2">
                            <a href="{php echo gWebUrl('auths/add')}"  class="btn btn-primary" >添加</a>
                            <a href="#" class="btn btn-danger js-delete">批量删除 </a>
                        </div>
                    </div>
                </form>
            </div>
            <div id="table">
                <table class="table table-striped table-bordered table-hover m-t-md">
                    <thead>
                    <tr>
                        <th >
                            <label for="batch_input"><input id="batch_input" type="checkbox" onclick="var ck = this.checked;$(':checkbox').each(function(){this.checked = ck});" /></label>
                        </th>
                        <th class="text-center">编号ID</th>
                        <th class="text-center">权限名称</th>
                        <th class="text-center">权限</th>
                        <th class="text-center">状态</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $aData $k $v}
                    <tr>
                        <td>
                            <input type="checkbox" name="checkbox[]" class="checkbox" value="{$v['id']}" />
                        </td>
                        <td class="text-center">{php echo ((max(1, intval($_GPC['page']))-1)*10)+$k+1}</td>
                        <td class="text-center">
                            {if $v['level'] == 2}&nbsp;&nbsp;&nbsp;{/if}
                            <span{if $v['level'] == 2 } class=" icon-angle-right" {/if}>
                            {$v['ptitle']}
                            </span>
                        </td>
                        <td class="text-center"> {$v['name']}</td>
                        <td class="text-center">
                            {if $v['status'] == 1}
                            <span class="label label-primary">启用</span>{else}
                            <span class="label label-warning">停用</span>{/if}
                        </td>
                        <td class="text-right">
                            {if $v['status'] == 1}
                            <a href="javascript:;" title="暂停"
                               onclick="return getConfirm('{php echo gWebUrl('auths/change',['id'=>$v['id'],'status' => 2])}', '是否暂停该记录?')"
                               class="btn btn-warning btn-xs"><i class="fa fa-pause"></i></a> {else}
                            <a href="javascript:;" title="启用"
                               onclick="return getConfirm('{php echo gWebUrl('auths/change',['id'=>$v['id'],'status' => 1])}', '是否启用该记录?')"
                               class="btn btn-success btn-xs"><i class="fa fa-play"></i></a> {/if}
                            <a href="{php echo gWebUrl('auths/edit',['id'=>$v['id']])}" title="编辑" class="btn btn-primary btn-xs"><i class="fa fa-pencil"></i></a>
                            <a href="javascript:;" title="删除"
                               onclick="return getConfirm('{php echo gWebUrl('auths/del',['id'=>$v['id']])}', '是否删除该记录?')"
                               class="btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
                {$aData['page']}
            </div>
    </div>
    <!--右侧部分结束-->
</div>
<script src="{$_W['siteroot']}../addons/{MOD_ADD}/static/admin/H/js/plugins/jeditable/jquery.jeditable.js"></script>
<!-- layerDate plugin javascript -->
<script src="{$_W['siteroot']}../addons/{MOD_ADD}/static/admin/H/js/plugins/layer/laydate/laydate.js"></script>
<script type="text/javascript">
    //日期范围限制
    var start = {
        elem: '#start',
        format: 'YYYY/MM/DD hh:mm:ss',
        min: '1900-01-1', //设定最小日期为当前日期
        max: '2099-06-16', //最大日期
        istime: true,
        istoday: false,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#end',
        format: 'YYYY/MM/DD hh:mm:ss',
        min: '1900-01-1', //设定最小日期为当前日期
        max: '2099-06-16', //最大日期
        istime: true,
        istoday: false,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);
</script>
<script type="text/javascript">
    document.querySelectorAll('.js-delete')[0].onclick = () => {
        var ids = [];
        var $checks = $('.checkbox:checkbox:checked');
        $checks.each(function () {
            if (this.checked) {
                ids.push(this.value);
            }
            ;
        });
        if (ids.length == 0) {
            layer.alert('请至少选择一个', {icon: 5});
            return;
        }
        layer.confirm('确定执行操作吗', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            const u = "{php echo gWebUrl('auths/del_all')}";
            $.post(u, {ids: ids}, function (data) {
                if (data.type == 'success') {
                    layer.alert(data.message, {icon: 1});
                    setTimeout(function () {
                        window.location.reload()
                    }, 2000);
                } else {
                    layer.alert(data.message, {icon: 5});
                    setTimeout("_postUrl('" + data.redirect + "')", 1000);
                }
            });

        }, function () {
            // 取消操作
        });
    }
</script>
<?php $this->display('foot') ?>
